var app = getApp();
var baseUrl = getApp().globalData.baseUrl;
var header = getApp().globalData.header;

function wxReq(url,method = "GET", data) {
  return new Promise((resolve, reject) => {
    wx.request({
      url: baseUrl+url,
      method,
      data,
      header: {
        'content-type': 'application/json',
        'Access-Token': wx.getStorageSync('token')
      },
      success: res => {
        resolve(res);
      },
      reject: err => {
        reject(err);
      }
    })
  })
}

function http(url, method = "GET", data) {
  return new Promise((resolve, reject) => {
    wx.request({
      url: baseUrl + url,
      method,
      data,
      header: {
        'content-type': 'application/json'
      },
      success: res => {
        resolve(res);
      },
      reject: err => {
        reject(err);
      }
    })
  })
}

function _objPost(url, method = "GET", data) {
  return new Promise((resolve, reject) => {
    wx.request({
      url: baseUrl + url,
      method,
      data,
      header: {
        "content-type": "application/x-www-form-urlencoded",
        'Access-Token': wx.getStorageSync('token')
      },
      success: res => {
        resolve(res);
      },
      reject: err => {
        reject(err);
      }
    })
  })
}



module.exports = {
  wxReq,
  http,
  _objPost,
}